package cn.virens.utils;

import cn.hutool.core.util.StrUtil;
import cn.virens.components.page.PageParamUser;

public class PermissionUtil {
	public static final String role_supermanage = "supermanage";
	public static final String role_manage = "manage";

	public static final String group_default = "default";

	public static boolean isGroupDefault(String group) {
		return StrUtil.containsAny(group, group_default);
	}

	public static boolean notGroupDefault(String group) {
		return !isRoleManage(group);
	}

	public static boolean isRoleManage(String role) {
		return StrUtil.containsAny(role, role_supermanage, group_default);
	}

	public static boolean notRoleManage(String role) {
		return !isRoleManage(role);
	}

	public static boolean isRoleSupermanage(String role) {
		return StrUtil.containsAny(role, role_supermanage);
	}

	public static boolean notRoleSupermanage(String role) {
		return !isRoleSupermanage(role);
	}

	public static boolean isCanViewAllData(PageParamUser param) {
		return isGroupDefault(param.getGroup()) || isRoleSupermanage(param.getRole());
	}

	public static String str(PageParamUser param) {
		return "FIND_IN_SET(res_group,'" + param.getGroup() + "')";
	}

	public static String str(PageParamUser param, String table) {
		return "FIND_IN_SET(" + table + "res_group,'" + param.getGroup() + "')";
	}
}
